<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>巴士管理管理</title>
<meta name="decorator" content="default" />
<script type="text/javascript">
		$(document).ready(function() {
			$("#licno").focus();
			$('#cargotypeid').bind('change',function(){
				$option = $(this).find('option:selected');
				$('#seats').val($option.attr('data-seats'));
				$('#lugage').val($option.attr('data-packs'));
				$('#iselectric').val($option.attr('data-iselectric'));
				$('#vehiclename').val($option.attr('data-typedesc'));
				$('#endurance').val($option.attr('data-continue'));
				$('#iselectric').trigger('change'); 
			});
			$('#cargotypeid').trigger('change'); 
			
			$("#inputForm").validate({
			    rules: {
			    	purchasedate: {datecmp:true},
			    	regdate:{datecmp:true},
			    	seatsforsale: {compare:true},
			    	licenseno: {remote: "${ctx}/bus/tCompBus/checkLicenseno?oldLicenseno=" + encodeURIComponent('${tCompBus.licenseno}')},
			    },
			    messages: {
			    	licenseno: {remote: "车牌号已存在"},
				},
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			$("input").prop("disabled", true);
			$("select").prop("disabled", true);
			$("#btnCancel").prop("disabled", false);
		});
		// 成人票和儿童票的总和不能为空
		$.validator.addMethod("compare", function(value, element) {
			var bigger = $('#seats').val();
			var smaller = $('#seatsforsale').val();
			if(parseInt(bigger)>=parseInt(smaller)){
				return true;
			} else {
				return false;
			}
		}, "可售座位数不能大于座位数");
		$.validator.addMethod("datecmp", function(value, element) {
			var bigdate = $('#regdate').val();
			var smadate = $('#purchasedate').val();
			if (bigdate != null && bigdate != "" && smadate != null && smadate != ""){
				var big=new Date(bigdate.replace("-", "/").replace("-", "/"));
				var small = new Date(smadate.replace("-", "/").replace("-", "/"));
				if(big<small){
					return true;
				} else {
					return false;
				}
			}else
			{
				return true;
			}
			
		}, "上牌日期必须大于购买日期！");
		//验证车牌号
		function lostBlur(){  
			 var re=/^[\u4e00-\u9fa5]{1}[A-Z]{1}[A-Z_0-9]{5}$/;

			 if(window.document.getElementById("licenseno").value.search(re)==-1)

			             {

			                 alert("输入的车牌号格式不正确");

			                 return false;

			             }
	    }  
		//验证手机号
		function checkPhone(){

			var sPhone = document.getElementById("ownertel").value ;

			if(!/^(13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i.test(sPhone))
			{
			  alert("输入手机号码有误");
			}

		} 
		//通过选择归属公司显示联系人id和司机
		function checkOwnerid(text,officeids){
			//通过选择归属公司显示联系人id
			//$(ownerid).val(text);
			//通过选择归属公司显示司机
			url = "${ctx}/bus/tCompBus/ajaxList";
			$.ajax({
		          dataType: 'json',
		            url:url,
		            data:{officeids:officeids},
		            type: 'POST',
		            cache:false,
		            success: function(data) {
		            	 var obj = eval(data);
		            	jQuery(maindriver).html('');
		            	jQuery(maindriver).append("<option value=''>请选择</option>");
		            	  $.each(obj, function (i, item) {
		            		 jQuery(maindriver).append("<option value='"+ item.drvssysid+"'>"+ item.drvname+"</option>");
		            	});
		            	  jQuery(vicedriver).html('');
		            	  jQuery(vicedriver).append("<option value=''>请选择</option>");
		            	  $.each(obj, function (i, item) {
		            		 jQuery(vicedriver).append("<option value='"+ item.drvssysid+"'>"+ item.drvname+"</option>");
		            	}); 
		            	  jQuery(thirddriver).html('');
		            	  jQuery(thirddriver).append("<option value=''>请选择</option>");
		            	  $.each(obj, function (i, item) {
		            		 jQuery(thirddriver).append("<option value='"+ item.drvssysid+"'>"+ item.drvname+"</option>");
		            	}); 
		            },
		            error: function() {
		            		 alert("数据有误");
		            }
		        });
			 url2 = "${ctx}/bus/tCompBus/cargoTypeList";
			/*  $.ajax({
		          dataType: 'json',
		            url:url2,
		            data:{officeids:officeids},
		            type: 'POST',
		            cache:false,
		            success: function(data) {
		            	var obj = eval(data);

		            	jQuery(cargotypeid).html('');
		            	jQuery(cargotypeid).append("<option value='' selected='selected'>--请选择--</option>");
		      			$.each(obj, function (i, item) {
		            		 jQuery(cargotypeid).append("<option value='"+ item.cargotypeid+"'>"+ item.typename+"</option>");
		            	});
		            },
		            error: function() {
		            		 alert("数据有误");
		            }
		        }); */
		} 
		//验证主司机和副司机不能为同一个人
	 	function checkDrv(drv){

			
			var zhuDrvObj =document.getElementById("maindriver");
			var fuDrvObj =document.getElementById("vicedriver");
			var zhuDrv = zhuDrvObj.options[zhuDrvObj.selectedIndex].value;
			var fuDrv = fuDrvObj.options[fuDrvObj.selectedIndex].value;
			console.log(zhuDrv);
			//console.log(fuDrv);
			 if(zhuDrv==fuDrv){
				alert("主司机和副司机不能为同一个人！");
			} 
		} 
		
	 	//根据是否纯电动车展示修改纯电动车最大行驶路程
		function iselectricChange(value) {
			if (value == 1) {
				document.getElementById("cont").style.display = "block";
			} else {
				document.getElementById("cont").style.display = "none";
				$(endurance).val(0);
			}
		}
	 	//车型描述默认为车型的名称
		function cargoTypeChange(value) {
			$("#vehiclename").val(value);
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/bus/tCompBus?types=${types}">巴士管理列表</a></li>
		<li class="active"><a
			href="${ctx}/bus/tCompBus/formview?id=${tCompBus.id}&types=${types}">巴士信息查看</a></li>
	</ul>
	<br />
	<form:form id="inputForm" modelAttribute="tCompBus" method="post"
		class="form-horizontal">
		<input type="hidden" id="types" name="types" value="${types}">
		<form:hidden path="id" />
		<sys:message content="${message}" />
		<div class="control-group">
			<label class="control-label">归属公司:</label>
			<div class="controls">
				<c:if test="${types==1}">
					<input type="hidden" id="office.id" name="office.id"  value="${tCompBus.office.id}">
	  				<input type="text" id="office.name" name="office.name" class="span4"
						value="${tCompBus.office.name}"   readonly="readonly">	
				</c:if>
				<c:if test="${types !=1}">
					<select name="office" class="span4 required"
						onchange="checkOwnerid(this.options[this.options.selectedIndex].text,this.options[this.options.selectedIndex].value)">
						<option value="">--请选择--</option>
						<c:forEach items="${officelist}" var="office">
							<option value="${office.id}"
								<c:if test="${office.id eq tCompBus.office.id}">selected="selected"</c:if>>
								${office.name}</option>
						</c:forEach>
					</select>
					<span class="help-inline"><font color="red">*</font> </span>

				</c:if>
				<%-- <input type="text"  id="office.id" name="office.id" value="${tCompBus.office.name}" readonly="readonly"> --%>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">车牌号：</label>
			<div class="controls">
				<form:input path="licenseno" htmlEscape="false" maxlength="20"
					class="span4 licno required" />
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">选择车型：</label>
			<div class="controls">
				<select id="cargotypeid" name="cartype.cargotypeid" class="span4 required">
					<option value="">--请选择--</option>
  				<c:forEach items="${tCargotypeList}" var="cartype">
						<option 
							data-seats="${cartype.seats}"
							data-packs="${cartype.packs}"
							data-typedesc="${cartype.typedesc}"
							data-iselectric="${cartype.iselectric}"
							data-continue="${cartype.continuerange}"
							value="${cartype.cargotypeid}"
							<c:if test="${ cartype.cargotypeid eq tCompBus.cartype.cargotypeid}">selected="selected"</c:if>>
							${cartype.typename}</option>
					</c:forEach>
				</select> <span class="help-inline"><font color="red">*</font> </span>
			</div>			
		</div>
		<div class="control-group">
			<label class="control-label">可乘座位数：</label>
			<div class="controls">
				<form:input path="seats" htmlEscape="false" readonly='true'
					class="span4  digits required" />
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">行李箱容量：</label>
			<div class="controls">
				<form:input path="lugage" htmlEscape="false" readonly='true'
					class="span4 digits required" />
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">车型描述：</label>
			<div class="controls">
				<form:input path="vehiclename" htmlEscape="false" maxlength="200"
					class="span4" />
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">车辆属性：</label>
			<div class="controls">
				<form:select path="bustype" class="span4">
					<form:option value="0" label="公营" />
					<form:option value="1" label="承包" />
				</form:select><span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">车辆品牌：</label>
			<div class="controls">
				<form:input path="brand" htmlEscape="false" maxlength="50"
					class="span4 required" />
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">车辆等级：</label>
			<div class="controls">
				<form:select path="busclass" class="span4">
					<option value="">--请选择--</option>
					<form:options items="${fns:getDictList('dbo_vehicle')}"
						itemLabel="label" itemValue="value" htmlEscape="false" />
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">动力类型：</label>
			<div class="controls">
				<form:select path="enginetype" class="span4">
					<option value="">--请选择--</option>
					<form:options items="${fns:getDictList('fueltype')}"
						itemLabel="label" itemValue="value" htmlEscape="false" />
				</form:select>
			</div>
		</div>
		<div class="control-group">
				<label class="control-label">是否纯电动车：</label>
				<div class="controls">
					<form:select path="iselectric" class="span4 required"
						onchange="iselectricChange(this.options[this.options.selectedIndex].value)">
						<form:options items="${fns:getDictList('yes_no')}"
							itemLabel="label" itemValue="value" htmlEscape="false" />
					</form:select>
					<span class="help-inline"><font color="red">*</font> </span>
				</div>
			</div>
			<div class="control-group" id="cont"
				<c:if test="${tCompBus.iselectric==0}">style="display:none"</c:if>>
				<label class="control-label">纯电动车最大续航里程（KM）：</label>
				<div class="controls">
				<form:input path="endurance" htmlEscape="false" 
					class="span4 digits" />
			</div>
			</div>
		<div class="control-group">
			<label class="control-label">车辆营运证号：</label>
			<div class="controls">
				<form:input path="certino" htmlEscape="false" maxlength="20"
					class="span4 digits" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">营运范围：</label>
			<div class="controls">
				<form:select path="operatearea" class="span4">
					<option value="">--请选择--</option>
					<form:options items="${fns:getDictList('dbo_operatearea')}"
						itemLabel="label" itemValue="value" htmlEscape="false" />
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">车辆颜色：</label>
			<div class="controls">
				<form:input path="bodycolor" htmlEscape="false" maxlength="20"
					class="span4" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">准驾类型：</label>
			<div class="controls">
				<form:select path="permittype" class="span4">
					<option value="">--请选择--</option>
					<form:options items="${fns:getDictList('permittype')}"
						itemLabel="label" itemValue="value" htmlEscape="false" />
				</form:select>
			</div>
		</div>
		<%-- <div class="control-group">
			<label class="control-label">车辆状态：</label>
			<div class="controls">
				<form:select path="busstatus" class="input-mini">
					<form:options items="${fns:getDictList('Y_N')}" itemLabel="label" itemValue="value" htmlEscape="false" />
				</form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div> --%>
		<div class="control-group">
			<label class="control-label">首次购车开票日期：</label>
			<div class="controls">
				<input name="regdate" id="regdate" type="text" readonly="readonly" 
					class="span4 Wdate"
					value="<fmt:formatDate value="${tCompBus.regdate}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">首次上牌登记日期：</label>
			<div class="controls">
				<input name="purchasedate" id="purchasedate" type="text" readonly="readonly"
					 class="span4 Wdate "
					value="<fmt:formatDate value="${tCompBus.purchasedate}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">乘运险：</label>
			<div class="controls">
				<%-- <select name="travelins" class="span4">
					<option value="">--请选择--</option>
					<option value="1"
						<c:if test="${not empty tCompBus.travelins and 1 eq tCompBus.travelins}">selected="selected"</c:if>>30万</option>
					<option value="2"
						<c:if test="${not empty tCompBus.travelins and 2 eq tCompBus.travelins}">selected="selected"</c:if>>40万</option>
					<option value="3"
						<c:if test="${not empty tCompBus.travelins and 3 eq tCompBus.travelins}">selected="selected"</c:if>>60万</option>
					<option value="4"
						<c:if test="${not empty tCompBus.travelins and 4 eq tCompBus.travelins}">selected="selected"</c:if>>80万</option>
				</select> --%>
				<form:select path="travelins" class="span4">
					<form:option value="" label="" />
					<form:options items="${fns:getDictList('dbo_travelins')}"
						itemLabel="label" itemValue="value" htmlEscape="false" />
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">第三者责任险：</label>
			<div class="controls">
				<%-- <select name="thirdins" class="span4">
					<option value="">--请选择--</option>
					<option value="1"
						<c:if test="${not empty tCompBus.thirdins and 1 eq tCompBus.thirdins}">selected="selected"</c:if>>800万</option>
					<option value="2"
						<c:if test="${not empty tCompBus.thirdins and 2 eq tCompBus.thirdins}">selected="selected"</c:if>>750万</option>
					<option value="3"
						<c:if test="${not empty tCompBus.thirdins and 3 eq tCompBus.thirdins}">selected="selected"</c:if>>700万</option>
					<option value="4"
						<c:if test="${not empty tCompBus.thirdins and 4 eq tCompBus.thirdins}">selected="selected"</c:if>>650万</option>
					<option value="5"
						<c:if test="${not empty tCompBus.thirdins and 5 eq tCompBus.thirdins}">selected="selected"</c:if>>600万</option>
					<option value="6"
						<c:if test="${not empty tCompBus.thirdins and 6 eq tCompBus.thirdins}">selected="selected"</c:if>>550万</option>
					<option value="7"
						<c:if test="${not empty tCompBus.thirdins and 7 eq tCompBus.thirdins}">selected="selected"</c:if>>500万</option>
					<option value="8"
						<c:if test="${not empty tCompBus.thirdins and 8 eq tCompBus.thirdins}">selected="selected"</c:if>>450万</option>
					<option value="9"
						<c:if test="${not empty tCompBus.thirdins and 9 eq tCompBus.thirdins}">selected="selected"</c:if>>400万</option>
					<option value="10"
						<c:if test="${not empty tCompBus.thirdins and 10 eq tCompBus.thirdins}">selected="selected"</c:if>>350万</option>
					<option value="11"
						<c:if test="${not empty tCompBus.thirdins and 11 eq tCompBus.thirdins}">selected="selected"</c:if>>300万</option>
					<option value="12"
						<c:if test="${not empty tCompBus.thirdins and 12 eq tCompBus.thirdins}">selected="selected"</c:if>>250万</option>
					<option value="13"
						<c:if test="${not empty tCompBus.thirdins and 13 eq tCompBus.thirdins}">selected="selected"</c:if>>200万</option>
					<option value="14"
						<c:if test="${not empty tCompBus.thirdins and 14 eq tCompBus.thirdins}">selected="selected"</c:if>>150万</option>
					<option value="15"
						<c:if test="${not empty tCompBus.thirdins and 15 eq tCompBus.thirdins}">selected="selected"</c:if>>100万</option>
										<option value ="15"
  					<c:if test="${ empty tCompBus.thirdins }">selected="selected"</c:if>>100万</option>

					<option value="16"
						<c:if test="${not empty tCompBus.thirdins and 16 eq tCompBus.thirdins}">selected="selected"</c:if>>50万</option>
					<option value="17"
						<c:if test="${not empty tCompBus.thirdins and 17 eq tCompBus.thirdins}">selected="selected"</c:if>>30万</option>
					<option value="18"
						<c:if test="${not empty tCompBus.thirdins and 18 eq tCompBus.thirdins}">selected="selected"</c:if>>20万</option>
					<option value="19"
						<c:if test="${not empty tCompBus.thirdins and 19 eq tCompBus.thirdins}">selected="selected"</c:if>>15万</option>
					<option value="20"
						<c:if test="${not empty tCompBus.thirdins and 20 eq tCompBus.thirdins}">selected="selected"</c:if>>10万</option>
					<option value="21"
						<c:if test="${not empty tCompBus.thirdins and 21 eq tCompBus.thirdins}">selected="selected"</c:if>>5万</option>
				</select> --%>
				<form:select path="thirdins" class="span4">
					<form:option value="" label="" />
					<form:options items="${fns:getDictList('dbo_thirdins')}"
						itemLabel="label" itemValue="value" htmlEscape="false" />
				</form:select>
			</div>
		</div>
		<%-- <div class="control-group">
			<label class="control-label">联系人ID：</label>
			<div class="controls">
				<form:input path="ownerid" htmlEscape="false" class="span4 required"
					readonly="true" value="${owner}" />
			</div>
		</div> --%>
		<div class="control-group">
			<label class="control-label">联系人：</label>
			<div class="controls">
				<form:input path="owner" htmlEscape="false" maxlength="30"
					class="span4 " />

			</div>
		</div>
		<div class="control-group">
			<label class="control-label">联系人手机：</label>
			<div class="controls">
				<form:input path="ownertel" htmlEscape="false" maxlength="20"
					class="span4 mobile " />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">年检日期：</label>
			<div class="controls">
				<input name="inspectdate" type="text" readonly="readonly"
					class="span4 Wdate "
					value="<fmt:formatDate value="${tCompBus.inspectdate}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">二维日期：</label>
			<div class="controls">
				<input name="ddate" type="text" readonly="readonly" 
					class="span4 Wdate "
					value="<fmt:formatDate value="${tCompBus.ddate}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});" />
			</div>
		</div>
		<%-- 	<div class="control-group">
			<label class="control-label">开始时间：</label>
			<div class="controls">
				<input name="startdate" type="text" id="startdate" maxlength="20" readonly="readonly" value="<fmt:formatDate value="${tCompBus.startdate}" pattern="yyyy-MM-dd"/>" class="Wdate" 
				onfocus="WdatePicker({dateFmt:'yyyy/MM/dd',maxDate:'#F{$dp.$D(\'enddate\')}'})"/> 
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">结束时间：</label>
			<div class="controls">
				<input name="enddate" type="text" id="enddate" maxlength="20" readonly="readonly" value="<fmt:formatDate value="${tCompBus.enddate}" pattern="yyyy-MM-dd"/>" class="Wdate" 
				onfocus="WdatePicker({dateFmt:'yyyy/MM/dd',minDate:'#F{$dp.$D(\'startdate\')}'})"/> 
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div> --%>
		<input type="hidden" id="zhuid" name="zhuid"
			value="${tCompBus.maindriver}">
		<input type="hidden" id="fuid" name="fuid"
			value="${tCompBus.vicedriver}">
			<input type="hidden" id="thuid" name="thuid"
			value="${tCompBus.thirddriver}">
		<div class="control-group">
			<label class="control-label">主司机：</label>
			<div class="controls">
				<select id="maindriver" name="maindriver" class="span4 required">
					<option value="">--请选择--</option>
					<c:forEach items="${tDrvlist}" var="drv">
						<option value="${drv.drvssysid}"
							<c:if test="${ drv.drvssysid eq tCompBus.maindriver}">selected="selected"</c:if>>
							${drv.drvname}</option>
					</c:forEach>
				</select> <span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">第一副司机：</label>
			<div class="controls">
				<select id="vicedriver" name="vicedriver" class="span4" noEqualTo="#maindriver">
					<option value="">--请选择--</option>
					<c:forEach items="${tDrvlist}" var="drv">
						<option value="${drv.drvssysid}"
							<c:if test="${ drv.drvssysid eq tCompBus.vicedriver}">selected="selected"</c:if>>
							${drv.drvname}</option>
					</c:forEach>
				</select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">第二副司机：</label>
			<div class="controls">
				<select id="thirddriver" name="thirddriver" class="span4" noEqualTo="#maindriver">
					<option value="">--请选择--</option>
					<c:forEach items="${tDrvlist}" var="drv">
						<option value="${drv.drvssysid}"
							<c:if test="${ drv.drvssysid eq tCompBus.thirddriver}">selected="selected"</c:if>>
							${drv.drvname}</option>
					</c:forEach>
				</select>
			</div>
		</div>

		<%--  <table id="tab1"  border="0"class="control-group" style="margin-left:100px;"  cellpadding="0" cellspacing="0" >
	      <thead>
	    <tr>
	   <!--   <th align="center" style=“border:0;” >选择</th> -->
	     <th align="center" style=“border:0;” >司机</th>
	    </tr>
	   </thead>
	   
               <tr >
     <!-- <td><input type=checkbox id="box1" onClick="GetRow()" />
         <input type="hidden" name="fuJ" id="fuJ1" />
     </td> -->
    
     <td> <select  name="drvssysid" class="input-xxlarges">  
  					<c:forEach items="${tCompBuslist}" var="tCompBuslist" ><option value ="${tCompBuslist.drvssysid}" id="drvssysids">${tCompBuslist.drvname}</option></c:forEach>  
				</select>  </td> 
            </tr>
          
       </table>
      
      
       <input type="button" name="Submit" value="增加一行" onclick="javascript:AddRow();" style="margin-left:100px"/> --%>
		<!-- <input type="button" name="Submit" value="删除" onclick="javascript:DelRow();" style="margin-left:100px"/>  -->
		<div class="form-actions">
			<input id="btnCancel" class="btn" type="button" value="返 回"
				onclick="history.go(-1)" />
		</div>
	</form:form>
</body>
</html>